package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskRewards;
import com.ruoyi.system.service.ITaskRewardsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务奖励方式Controller
 * 
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/system/rewards")
public class TaskRewardsController extends BaseController
{
    @Autowired
    private ITaskRewardsService taskRewardsService;

    /**
     * 查询任务奖励方式列表
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskRewards taskRewards)
    {
        startPage();
        List<TaskRewards> list = taskRewardsService.selectTaskRewardsList(taskRewards);
        return getDataTable(list);
    }

    /**
     * 导出任务奖励方式列表
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:export')")
    @Log(title = "任务奖励方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskRewards taskRewards)
    {
        List<TaskRewards> list = taskRewardsService.selectTaskRewardsList(taskRewards);
        ExcelUtil<TaskRewards> util = new ExcelUtil<TaskRewards>(TaskRewards.class);
        util.exportExcel(response, list, "任务奖励方式数据");
    }

    /**
     * 获取任务奖励方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:query')")
    @GetMapping(value = "/{taskRewardId}")
    public AjaxResult getInfo(@PathVariable("taskRewardId") Long taskRewardId)
    {
        return success(taskRewardsService.selectTaskRewardsByTaskRewardId(taskRewardId));
    }

    /**
     * 新增任务奖励方式
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:add')")
    @Log(title = "任务奖励方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskRewards taskRewards)
    {
        return toAjax(taskRewardsService.insertTaskRewards(taskRewards));
    }

    /**
     * 修改任务奖励方式
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:edit')")
    @Log(title = "任务奖励方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskRewards taskRewards)
    {
        return toAjax(taskRewardsService.updateTaskRewards(taskRewards));
    }

    /**
     * 删除任务奖励方式
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:remove')")
    @Log(title = "任务奖励方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskRewardIds}")
    public AjaxResult remove(@PathVariable Long[] taskRewardIds)
    {
        return toAjax(taskRewardsService.deleteTaskRewardsByTaskRewardIds(taskRewardIds));
    }
}
